import * as Constant from '@/constant/index.js'

// api判断么有登录跳转到登录页
export const toAppLogin = (url = '/pages/index/index') => {
  uni.removeStorageSync('wxlsToken')
  if (window.h5uni) {
  	navTo(url)
  } else {
  	document.addEventListener('UniAppJSBridgeReady', async () => {
  		navTo(url)
  	})
  }
  return
}

const navTo = (url) => {
	let data = url
	if(data.includes('?')) {
		data = `${data}&time=${new Date().getTime()}`
	} else {
		data = `${data}?time=${new Date().getTime()}`
	}
	let navToUrl = encodeURIComponent(
		`${
			process.env.NODE_ENV === 'development'
				? Constant.DEV_FRONTURL
				: Constant.PRO_FRONTURL
		}/#${data}`
	)
	h5uni['redirectTo']({
		url: '/pages/user/back_login?url=' + navToUrl
	})
}
